package main

import (
	"fmt"
	"sync"
)

type Player struct {
	ID int32
	Name string
}

func main(){
	sm := sync.Map{}
	sm.Store(1, "a")
	sm.Store(2, &Player{1,"test"})
	if v, ok := sm.Load(1); ok{
		fmt.Println(v)
	}

	value, ok := sm.Load(2)
	if !ok  {
		fmt.Println("sm Load error")
	}
	//对象反射
	player := value.(*Player)
	fmt.Println("player ", player.Name, player.ID)

	if v, ok := sm.LoadOrStore(2, "c"); ok{
		fmt.Println(v)
	}
	//遍历map
	sm.Range(func(k, v interface{}) bool{
		fmt.Println(k, v)
		return true
	})


}
